package test;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;

public class HttpConn {

	public static void main(String[] args) {
		
		try {
			URL url = new URL("Http://git.icngor.com/new.json");
			HttpURLConnection conn = (HttpURLConnection) url.openConnection();
			//conn.setDoOutput(true);
			//conn.setDoInput(true);
			//conn.setConnectTimeout(5000);
			//conn.setRequestMethod("GET");
			//conn.connect();
			//向服务器发送字符串
//			OutputStream os = conn.getOutputStream();
//			os.write("{json:'json'}".getBytes());
//			os.flush();
//			os.close();
			if(conn.getResponseCode() == 200){
				//客户端接受字符串
				InputStream is = conn.getInputStream();
				BufferedReader br = new BufferedReader(new InputStreamReader(is));
				String str = "";
				StringBuffer sb = new StringBuffer();
				while((str = br.readLine()) != null){
					sb.append(str+"\n");
				}
				
				System.out.print(sb.toString());
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

}


/*

   		String wen = "MS2201828";
        String btnSearch = "EMS快递查询";
        URL url = new URL("http://www.kd185.com/ems.php");
        
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("POST");// 提交模式
        // conn.setConnectTimeout(10000);//连接超时 单位毫秒
        // conn.setReadTimeout(2000);//读取超时 单位毫秒
        conn.setDoOutput(true);// 是否输入参数

        StringBuffer params = new StringBuffer();
        // 表单参数与get形式一样
        params.append("wen").append("=").append(wen).append("&")
              .append("btnSearch").append("=").append(btnSearch);
        byte[] bypes = params.toString().getBytes();
 
        conn.getOutputStream().write(bypes);// 输入参数
        
        InputStream inStream=conn.getInputStream();
        System.out.println(new String(StreamTool.readInputStream(inStream), "gbk"));

 */
